package com.mapper;

import com.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    //查询用户
    //查询全部用户
    @Select("select * from user")
    List<User> findAllUser();
    //根据用户名模糊查询
    @Select("select * from user where user_name like \'%${name}%\'")
    List<User> findUserByName(@Param("name")String name);
    //根据ID查询
    @Select("select * from user where user_id =#{id}")
    User findUserById(@Param("id") int id);
    //根据邮箱模糊查询
    @Select("select * from user where user_email like \'%${email}%\'")
    List<User> findUserByEmail(@Param("email")String email);

    //注册时查询是否存在在
    @Select("select * from user where user_name = #{name}")
    User findUserName(@Param("name") String name);


    //查询全部用户数
    @Select("select count(*) from User")
    int count();

    /**
     * 分页查询
     * @param rows 第rows页
     * @param offset 页条数
     * @return
     */
    @Select("select * from User ORDER BY user_id LIMIT #{rows}, #{offset}")
    List<User> findUserPage(@Param("rows") int rows, @Param("offset") int offset);


    //增加用户
    @Insert("insert into User (user_ip,user_name,user_password,user_email,user_avatar,user_description,user_tel,user_update_time,user_create_time) value(#{user_ip},#{user_name},#{user_password},#{user_email},#{user_avatar},#{user_description},#{user_tel},#{user_update_time},#{user_create_time})")
    int addUser(User User);

    //修改用户资料
    @Update("update User set user_name=#{name},user_email=#{email},user_avatar=#{avatar},user_description=#{description},user_tel=#{tel},user_update_time=#{update_time} where user_id = #{id}")
    int updateUserById(@Param("id")int id,@Param("name") String name, @Param("email")String email, @Param("avatar")String avatar, @Param("description")String description,@Param("tel")String tel,@Param("update_time")String update_time);

    //查询密码
    @Select("select user_password from User where user_id = #{id}")
    String findPdById(@Param("id") int id);

    //修改用户密码
    @Update("update User set user_password=#{newPassword} where user_id = #{id}")
    int updateUserPd(@Param("newPassword") String newPassword,@Param("id") int id);


    //删除用户
    @Delete("delete from User where user_id =#{id}")
    int delUserById(@Param("id")int id);

}
